package com.tuocent.dagv2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tuocent.dagv2.common.AjaxResult;
import com.tuocent.dagv2.common.utils.SnowFlakeID;
import com.tuocent.dagv2.entity.ArchivesImportLog;
import com.tuocent.dagv2.mapper.ArchivesImportLogMapper;
import com.tuocent.dagv2.service.IArchivesImportLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Vincent
 * @since 2025-09-12
 */
@Service
public class ArchivesImportLogServiceImpl extends ServiceImpl<ArchivesImportLogMapper, ArchivesImportLog> implements IArchivesImportLogService {
    @Resource
    private SnowFlakeID snowFlakeID;

    @Override
    public AjaxResult getArchivesImportLog(String pid, Integer page, Integer limit) {
        QueryWrapper<ArchivesImportLog> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("pid", pid)
                .orderByAsc("result")
                .orderByAsc("idx");
        Page<ArchivesImportLog> log = page(new Page<>(page, limit), queryWrapper);
        return AjaxResult.success(log.getRecords(), log.getTotal());
    }

    @Override
    public void ImportLogData(String pid, int idx, String info) {
        ArchivesImportLog data = new ArchivesImportLog();
        data.setId(snowFlakeID.getId());
        data.setPid(pid);
        data.setIdx(idx);
        data.setInfo(info);
        data.setResult("失败");
        save(data);
    }
}
